package com.monna.adapter;

import android.content.Context;
import android.graphics.Paint;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.monna.entity.Score;
import com.monna.games_2048.R;
import com.monna.util.UserUtil;

import java.util.ArrayList;

/**
 * 继承GamesBaseAdapter，在convert（）方法里，实现自己的数据设置
 * @author 廖梦青
 */
public class LeadercoardAdapter extends BaseAdapter {

    private ArrayList<Score> data;
    private Context context;

    public LeadercoardAdapter(ArrayList data, Context context) {
        this.data = data;
        this.context = context;
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if(convertView ==null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.layout_leaderboard, parent, false);
        }
        //初始化item的各个组件
        final TextView rank = convertView.findViewById(R.id.val_ranking);
        final TextView name = convertView.findViewById(R.id.val_name);
        final TextView score = convertView.findViewById(R.id.val_highestScore);
        rank.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
        rank.setText("1"+"");
        String userName = new UserUtil(context).seleUserName(data.get(position).getAccount());
        name.setText(userName+"");
        score.setText(data.get(position).getHeightScore()+"");
        return convertView;
    }
}
